def function-Name(self,argument1,argument2,...): Statements ---------- return value
class Rectangle : def setDimension(self,x,y): self.length = x self.breadth = y def area(self): a = self.length*self.breadth return a a = Rectangle() b = Rectangle() a.setDimension(5,7) b.setDimension(10,20) z = a.area()+b.area() print("Total Area is ",z) print("Area of a is ",a.area()) print("Area of b is ",b.area())
Total Area is 235 Area of a is 35 Area of b is 200
class worker: def setData(self,n,w,d): self.name=n self.wages=w self.wdays=d def showData(self): print("Name is ",self.name) print("Wages is ",self.wages) print("Wdays is ",self.wdays) def payment(self): p=self.wages*self.wdays return p a=worker() b=worker() a.setData("Raja",500,5) b.setData("Gaja",400,8) a.showData() print("Payment is ",a.payment()) b.showData() print("Payment is ", b.payment()) z = a.payment() + b.payment() print("Total Payment is ",z)
Name is Raja Wages is 500 Wdays are 5 Payment is 2500 Name is Gaja Wages is 400 Wdays are 8 Payment is 3200 Total Payment is 5700
class Set: def setData(self,x,y,z): self.n1=x self.n2=y self.n3=z def sum(self): s=self.n1+self.n2+self.n3 return s def mean(self): m=self.sum()/3 return m a=Set() b=Set() a.setData(2,5,3) b.setData(6,10,4) z = a.sum() + b.sum() print("Total Sum is ",z) print("Mean of b is ",b.mean())
Total Sum is 30 Mean of set b is 6.666667